/*
 * @Author: heinan
 * @Date: 2021-07-14 17:18:59
 * @Last Modified by: heinan
 * @Last Modified time: 2021-07-14 18:04:23
 */

import { createStore, combineReducers, applyMiddleware } from "redux";
import reduxThunk from "redux-thunk";

const modelCreator = function () {
  // 读取model目录下的ts|js文件
  const context = require.context("./modules", false, /\.(js)$/);
  // 获取model目录下的js文件路径
  const fileskey = context.keys();
  const model = {};
  // 遍历文件路径
  fileskey.forEach((key) => {
    // 根据文件路径获得文件内容
    const filecontext = context(key).default;
    // 将读取到的文件内容，以key、value形式绑定到model对象
    model[filecontext.name] = filecontext;
  });
  // 将动态生成的对象抛出
  return model;
};
const rootReducer = combineReducers(modelCreator());
const store = createStore(rootReducer, applyMiddleware(reduxThunk));
export default store;
